package com.sc.base.user.web;

import com.sc.base.user.bean.dto.user.*;
import com.sc.base.user.service.UserService;
import com.sc.commons.base.dto.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Random;
import java.util.stream.Collectors;

/**
 * @author
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired private UserService userService;

    @PostMapping("/add")
    public UserAddResDto add(@RequestBody UserAddReqDto reqDto){
        UserAddResDto resDto = new UserAddResDto();
        int i = new Random().nextInt(20);
        resDto.setId(i);
        return resDto;
    }

    @PostMapping("/list")
    public UserListResDto list(@RequestBody UserListReqDto reqDto){
        UserListResDto resDto = new UserListResDto();

        resDto.setData(new ArrayList<UserListDetailResDto>(){{
                            add(new UserListDetailResDto(1L, "mk", "1503781915X"));
                        }}.stream()
                        .filter(e->  StringUtils.hasText(reqDto.getPhone())&&reqDto.getPhone().contains(e.getPhone() )
                        ).collect(Collectors.toList()));

        resDto.setTotal(1L);
        return resDto;
    }

    @GetMapping("/test")
    public BaseResponse test(){

//        userService.save();
//
//        userService.getEntity();
//
//        userService.update();
//
//        userService.delete();

//        userService.save();

//        userService.getEntityTest();

//        userService.getTest();

//        userService.findEntity();

//        userService.find();

//        userService.execute();

//        userService.count();

        userService.jpqlUtils();



        return BaseResponse.ok();
    }
}
